<template>
	<div class="top">
		<el-row>
			<el-col :span="12" class="logo">
				<i class="iconfont icon-index" @click="goHome"></i>{{global.triageName}}
			</el-col>
			<el-col :span="12">
					<el-row>
						<el-col class="menu">
							<router-link to="/" target="_blank">新增</router-link>
							<a href="javascript:void(0)" @click="storageInfo('0')">暂存</a>
							<a href="javascript:void(0)" @click="openConfirm">归档</a>
							<el-dropdown trigger="click">
								<span class="menuTitle"><a href="javascript:void(0)">综合<i class="el-icon-arrow-down el-icon--right"></i></a></span>
								<el-dropdown-menu slot="dropdown" class="dropMenu">
									<!-- <el-dropdown-item>
										<a href="javascript:void(0)" @click="openDrug">取药</a>
									</el-dropdown-item> -->
									<el-dropdown-item>
										<recipe></recipe>
									</el-dropdown-item>
									<el-dropdown-item>
										<a href="javascript:void(0)" @click="openExam">检查</a>
									</el-dropdown-item>
									<el-dropdown-item>
										<time-node></time-node>
									</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
							
							<el-dropdown trigger="click">
								<span class="menuTitle">
									<a href="javascript:void(0)">管理<i class="el-icon-arrow-down el-icon--right"></i>
									</a>
								</span>
								<el-dropdown-menu slot="dropdown" class="dropMenu">
									<!-- <el-dropdown-item>
										<router-link to="/search" target="_blank">查询</router-link>
									</el-dropdown-item> -->
									<el-dropdown-item>
										<router-link to="/triages" target="_blank">分诊记录</router-link>
									</el-dropdown-item>
									<el-dropdown-item>
										<router-link to="/statistic" target="_blank">信息统计</router-link>
									</el-dropdown-item>
									<!-- <el-dropdown-item>
										<router-link to="/" target="_blank">导出</router-link>
									</el-dropdown-item> -->
								</el-dropdown-menu>
							</el-dropdown>
							<el-dropdown trigger="click">
								<span class="menuTitle"><a href="javascript:void(0)">{{curUser.userNickName+curUser.userName}}<i class="el-icon-arrow-down el-icon--right"></i></a></span>
								<el-dropdown-menu slot="dropdown" class="dropMenu">
									<!-- <el-dropdown-item disabled>
										<a href="javascript:void(0)">修改密码</a>
									</el-dropdown-item> -->
									<el-dropdown-item>
										<router-link to="/about/help" target="_blank">帮助反馈</router-link>
									</el-dropdown-item>
									<el-dropdown-item>
										<a href="javascript:void(0)" @click="logOut">退出登录</a>
									</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
						</el-col>
						<el-col class="waitList">
							<label v-if="waitList.length==0">(无人就诊)</label>
							<label v-if="waitList.length!=0">【当前共{{waitList.length}}人】</label>
							<label>待诊中:</label>
							<el-select v-model="selectWait" class="wait" style="width:110px;" :placeholder="'待诊中'+wait1List.length+'人'" @change="reBind('1')">
								<el-option
									v-for="item in wait1List"
									:key="item.recordUUID"
									:value="item.recordUUID">
									<span :class="pointerCSS[item.recordLight]">
										<i class="el-icon-caret-right"></i>
									</span>
									{{item.recordName+item.recordCard+'---'+item.startTime}}
								</el-option>
							</el-select>

							<label>检查中:</label>
							<el-select v-model="selectCheck" class="wait" style="width:110px;" :placeholder="'检查中'+wait2List.length+'人'" @change="reBind('2')">
								<el-option
									v-for="item in wait2List"
									:key="item.recordUUID"
									:value="item.recordUUID">
									<span :class="pointerCSS[item.recordLight]">
										<i class="el-icon-caret-right"></i>
									</span>
									{{item.recordName+item.recordCard+'---'+item.startTime}}
								</el-option>
							</el-select>
						</el-col>
					</el-row>
			</el-col>
		</el-row>
		<el-dialog
		  title="请确认是否归档下面患者"
		  :visible.sync="storageDialog"
		  width="560px">
		  <el-row class="confirmContent">
		  	<el-col :span="12"><label>就诊卡号：</label>{{patient.cardId}}</el-col>
		  	<el-col :span="12"><label>患者姓名：</label>{{patient.name}}</el-col>
		  	<el-col :span="12"><label>患者性别：</label>{{patient.sex}}</el-col>
		  	<el-col :span="12"><label>患者年龄：</label>{{patient.age}}</el-col>
		  </el-row>
		  <span slot="footer" class="dialog-footer">
		    <el-button type="primary" @click="storageDialog = false;storageInfo('1')">确 定</el-button>
		    <el-button @click="storageDialog = false">取 消</el-button>
		  </span>
		</el-dialog>
	</div>
</template>
<script type="text/javascript">
	import TimeNode from '@/components/TimeNode'
	import Recipe from '@/components/Recipe'
	export default{
		name: "Top",
		components:{TimeNode,Recipe},
		data(){
			return {
				selectWait:'',
				selectCheck:'',
				waitList:[],
				wait1List:[],
				wait2List:[],
				curUser:{},
				pointerCSS:{
					"1":"whitePoint",
					"2":"greenPoint",
					"3":"yellowPoint",
					"4":"redPoint"
				},
				storageDialog: false
			}
		},
		mounted(){
			if (this.$cookies.get("curUser")) {
				this.curUser = this.$cookies.get("curUser");
			}
			var vm = this;
			if (vm.timerFlag.flag) {
				clearTimeout(vm.timerFlag.flag);
			}
			vm.getWaitTimer();
		},
		beforeDestroy() {
		    clearInterval(this.timerFlag.flag);
		},
		computed:{
			patient:{
				set(value){
				},
				get(){
					return this.$store.state.patient;
				}
			},
			light(){
				return this.$store.state.light;
			},
			openDialog:{
				set(value){
				},
				get(){
					return this.$store.state.openDialog;
				}
			},
			saveFlag(){
				return this.$store.state.saveFlag;
			},
			timerFlag:{
				set(value){
				},
				get(){
					return this.$store.state.timerFlag;
				}
			},
			reData:{
				set(value){
				},
				get(){
					return this.$store.state.reData;
				}
			},
		},
		methods:{
		    logOut:function(){
		      this.$axios.logOut();
		      this.$cookies.remove("token");
			  this.$cookies.remove("curUser");
			  this.$router.push({path:'/login'});
		    },
		    reFresh:function(){
		    	window.location.reload();
		    },
		    goHome:function(){
		    	this.$router.push({path:'/'});
		    },
		    openExam:function(){
		    	if (!this.patient.complaintName) {
		    		this.openDialog.name = "openExam";
		    		this.openDialog.timeStamp = new Date().getTime();
		    	}else{
		    		this.$notify({
		                  title: '操作禁止',
		                  message: "当前已进入诊断，请使用处置列表内的开检查功能",
		                  type: 'warning'
		                });
		    	}
		    },
		    openDrug:function(){
		    	if (!this.patient.complaintName) {
		    		this.openDialog.name = "openDrug";
		    		this.openDialog.timeStamp = new Date().getTime();
		    	}else{
		    		this.$notify({
		                  title: '操作禁止',
		                  message: "当前已进入诊断，请使用处置列表内的开药功能",
		                  type: 'warning'
		                });
		    	}
		    },
		    openConfirm:function(){
		    	this.storageDialog = true;
		    },
		    setPatientNormal:function(){
				var vm =this;
				var lights = vm.light.manualLight+"_"+vm.light.lifeLight+"_"+vm.light.diseaseLight;
				if (vm.light.curLight=="1"||vm.light.curLight=="2") {
					vm.patient.normal = "良好";
				}else if (vm.light.curLight=="3"&&lights.split("3").length==2) {
					vm.patient.normal = "尚可";
				}else if (vm.light.curLight=="3"&&lights.split("3").length>2) {
					vm.patient.normal = "较差";
				}else if (vm.light.curLight=="4"&&lights.split("4").length==2) {
					vm.patient.normal = "差";
				}else if (vm.light.curLight=="4"&&lights.split("4").length>2) {
					vm.patient.normal = "极差";
				}
			},
		    storageInfo:function(type){
		    	var vm = this;
		    	if (!vm.patient.cardId&&!vm.patient.name) {
		    		vm.$notify({
		                  title: '非法操作',
		                  message: "无卡号且无姓名的患者，禁止暂存或归档！",
		                  type: 'warning'
		                });
		    		return false;
		    	}
		    	vm.setPatientNormal();
		    	var record = {
		    		recordUUID:vm.patient.patientUUID?vm.patient.patientUUID:null,
		    		nodeUUID:vm.patient.nodeUUID?vm.patient.nodeUUID:null,
		    		recordCard:vm.patient.cardId?vm.patient.cardId:null,
		    		hospitalCode:vm.curUser.hospitalCode?vm.curUser.hospitalCode:null,
		    		recordName:vm.patient.name?vm.patient.name:null,
		    		recordSex:vm.patient.sex?vm.patient.sex:null,
		    		recordAge:vm.patient.age?vm.patient.age:null,
		    		recordTel:vm.patient.telphone?vm.patient.telphone:null,
		    		recordAddress:vm.patient.address?vm.patient.address:null,
		    		recordSense:vm.patient.sense?vm.patient.sense:null,
		    		recordTemperature:vm.patient.temperature?vm.patient.temperature:null,
		    		recordPulseRate:vm.patient.pulseRate?vm.patient.pulseRate:null,
		    		recordPulseRhythm:vm.patient.pulseRhythm?vm.patient.pulseRhythm:null,
		    		recordBreathRate:vm.patient.breathRate?vm.patient.breathRate:null,
		    		recordBreathRhythm:vm.patient.breathRhythm?vm.patient.breathRhythm:null,
		    		recordSBP:vm.patient.sbp?vm.patient.sbp:null,
		    		recordDBP:vm.patient.dbp?vm.patient.dbp:null,
		    		recordAllergy:vm.patient.allergy?vm.patient.allergy.join(","):null,
		    		recordDiseaseTime:vm.patient.diseaseTime?vm.patient.diseaseTime:null,
		    		departTime:vm.patient.departTime?vm.patient.departTime:null,
		    		recordLight:vm.light.curLight,
		    		recordManualLight:vm.light.manualLight,
		    		is120:vm.patient.is120?"true":"false",
		    		isGreen:vm.patient.isGreen?"true":"false",
		    		handlePlace:vm.patient.handlePlace?vm.patient.handlePlace:null,
		    		handleTime:vm.patient.handleTime?vm.patient.handleTime:null,
		    		triageTime:vm.patient.triageTime?vm.patient.triageTime:null,
		    		nurse:vm.patient.nurse?vm.patient.nurse:null,
		    		doctor:vm.patient.doctor?vm.patient.doctor:null,
		    		result:vm.patient.handleResult?vm.patient.handleResult:null,
		    		sendDept:vm.patient.department?vm.patient.department:null,
		    		complaintCode:vm.patient.complaintCode?vm.patient.complaintCode:null,
		    		complaintName:vm.patient.complaintName?vm.patient.complaintName:null,
		    		recordSymptom:vm.patient.patientSymptoms?vm.patient.patientSymptoms:null,
		    		doctorDisease:vm.patient.doctorDisease?vm.patient.doctorDisease:null,
		    		doctorDisposal:vm.patient.doctorDisposal?vm.patient.doctorDisposal:null,
		    		disposalAdvice:vm.patient.doctorDisposalAdvice?vm.patient.doctorDisposalAdvice:null,
		    		nurseSymptom:vm.patient.nurseSymptom?vm.patient.nurseSymptom:null,
		    		nurseDisease:vm.patient.nurseDisease?vm.patient.nurseDisease:null,
		    		nurseDisposal:vm.patient.checkNurseDisposal?vm.patient.checkNurseDisposal:null,
		    		mews:vm.patient.mews?vm.patient.mews:"-1",
		    		general:vm.patient.normal?vm.patient.normal:null,
		    		startTime:vm.patient.startTime?vm.patient.startTime:vm.commonUtil.dateFormat(new Date(),'yyyy-MM-dd hh:mm:ss'),
		    	};
		    	if (type=="0") {
		    		record.status = "0";
		    		//console.log("执行暂存");
		    	}else if (type=="1") {
		    		record.status = "1";
		    		//console.log("执行归档");
		    	}
		    	vm.$axios.addRecord(record).then(function(res){
		    		if (res.data&&res.data.code&&res.data.code==200) {
		    			window.location.reload();
		    		}else{
		    			vm.$notify({
		                  title: '操作失败',
		                  message: "添加或更新记录失败，请重新尝试！",
		                  type: 'error'
		                });
		    		}
		    	},function(res){
		    		console.log("error:"+res);
		    	});
		    },
		    getWaitTimer:function(){
		    	var vm =this;
		    	if (window.$cookies.get("token")&&window.$cookies.get("token")!="null") {
					vm.$axios.getWaits(vm.curUser).then(function(res){
						if (res.data&&res.data.data) {
							vm.waitList = res.data.data;
						}else{
							vm.waitList = [];
						}
						vm.wait1List=[];
						vm.wait2List=[];
						vm.waitList.forEach(function(item){
							if (item.complaintName) {
								vm.wait2List.push(item);
							}else{
								vm.wait1List.push(item);
							}
						});
					},function(res){
						console.log("error:"+res);
					});
				}
				vm.timerFlag.flag=setTimeout(vm.getWaitTimer,10000);
		    },
		    reBind:function(origin){
		    	console.log(origin);
		    	var UUID ="";
		    	var vm = this;
		    	if (origin=="1") {
		    		UUID = vm.selectWait;
		    		vm.selectCheck ="";
		    	}else{
		    		UUID = vm.selectCheck;
		    		vm.selectWait ="";
		    	}
		    	if (UUID!="") {
		    		vm.$axios.getRecordByUUID(UUID).then(function(res){
		    			if (res.data&&res.data.data) {
		    				var record = res.data.data;
		    				vm.$set(vm.patient,'patientUUID',record.recordUUID);
		    				vm.$set(vm.patient,'nodeUUID',record.nodeUUID);
		    				vm.$set(vm.patient,"name",record.recordName);
		    				vm.$set(vm.patient,"sex",record.recordSex);
		    				vm.$set(vm.patient,"cardId",record.recordCard);
		    				vm.$set(vm.patient,"hospitalCode",record.hospitalCode);
		    				vm.$set(vm.patient,"age",record.recordAge);
		    				vm.$set(vm.patient,"telphone",record.recordTel);
		    				vm.$set(vm.patient,"address",record.recordAddress);
		    				vm.$set(vm.patient,"sense",record.recordSense);
		    				vm.$set(vm.patient,"temperature",record.recordTemperature);
		    				vm.$set(vm.patient,"pulseRhythm",record.recordPulseRhythm);
		    				vm.$set(vm.patient,"pulseRate",record.recordPulseRate);
		    				vm.$set(vm.patient,"breathRate",record.recordBreathRate);
		    				vm.$set(vm.patient,"breathRhythm",record.recordBreathRhythm);
		    				vm.$set(vm.patient,"sbp",record.recordSBP);
		    				vm.$set(vm.patient,"dbp",record.recordDBP);
		    				vm.$set(vm.patient,"allergy",record.recordAllergy==""?[]:record.recordAllergy.split(","));
		    				vm.$set(vm.patient,"diseaseTime",record.recordDiseaseTime);
		    				vm.$set(vm.patient,"departTime",record.departTime);
		    				vm.$set(vm.light,"curLight",record.recordLight);
		    				vm.$set(vm.light,"manualLight",record.recordManualLight);
		    				vm.$set(vm.patient,"is120",record.is120=="true"?true:false);
		    				vm.$set(vm.patient,"isGreen",record.isGreen=="true"?true:false);
		    				vm.$set(vm.patient,"handlePlace",record.handlePlace);
		    				vm.$set(vm.patient,"handleTime",record.handleTime);
		    				vm.$set(vm.patient,"triageTime",record.triageTime);
		    				vm.$set(vm.patient,"nurse",record.nurse);
		    				vm.$set(vm.patient,"doctor",record.doctor);
		    				vm.$set(vm.patient,"department",record.sendDept);
		    				vm.$set(vm.patient,"handleResult",record.result);
		    				vm.$set(vm.patient,"complaintCode",record.complaintCode);
		    				vm.$set(vm.patient,"complaintName",record.complaintName);
		    				vm.$set(vm.patient,"nurseSymptom",record.nurseSymptom);
		    				vm.$set(vm.patient,"nurseDisease",record.nurseDisease);
		    				vm.$set(vm.patient,"mews",record.mews);
		    				vm.$set(vm.patient,"startTime",record.startTime);

				    		vm.reData.patient = record;

		    			}
		    		},function(res){
		    			console.log("error:"+res)
		    		});
		    	}
		    }
		 },
		 watch:{
			saveFlag:{
				handler(curVal,oldVal){
					if (curVal.flag&&curVal.flag!="") {
						this.storageInfo("1");
					}
				},
				deep:true
			},
		}
	}
</script>
<style type="text/css" scoped>
	.top{
		background-color: #1e90ff;
		height: 70px;
	}
	.logo{
		color: #ffffff;
		text-align: left;
		letter-spacing: 10px;
		font-size: 24pt;
		line-height: 70px;
		padding-left: 15px;
	}
	.icon-index{
		font-size: 28pt;
		cursor: pointer;
	}
	.menu a:link{
		color: #ffffff;
		text-decoration: none;
	}
	.menu a:hover{
		color: #ff0000;
		font-weight: bolder;
	}
	.menu a:visited{
		color: #ffffff;
		text-decoration: none;
	}
	.menu a{
		margin-right: 15px;
	}
	.menu{
		text-align: right;
		line-height: 35px;
		padding-right: 15px;
	}
	.menuTitle{
		color: #ffffff;
		cursor: pointer;
		font-size: 12pt;
	}
	.waitList{
		color: #ffa500;
		text-align: right;
		padding-right: 15px;
		margin-top: 4px;
	}
	.dropMenu a:VISITED{
		color: #000000;
		text-decoration: none;
	}
	.dropMenu a:LINK{
		color: #000000;
		text-decoration: none;
	}
	.dropMenu a:HOVER{
		color: #ff0000;
		font-weight: bolder;
	}
	.whitePoint{
		font-size: 18pt;
		color: #FFFFFF;
	}
	.greenPoint{
		font-size: 18pt;
		color: #228B22;
	}
	.yellowPoint{
		font-size: 18pt;
		color: #FFD700;
	}
	.redPoint{
		font-size: 18pt;
		color: #FF0000;
	}
	.confirmContent{
		text-align: left;
		line-height: 35px;
		font-size: 12pt;
	}
	.confirmContent label{
		font-weight: bolder;
	}

</style>